package com.example.novelstory.controller.lxy;

import com.alibaba.fastjson.JSONObject;
import com.example.novelstory.entity.User;
//import com.example.novelstory.service.lxy.UserService;
import com.example.novelstory.service.lxy.UserServiceImpl;
import com.example.novelstory.utill.Constants;
import com.example.novelstory.utill.Result;

import com.tencentcloudapi.sms.v20190711.models.SendStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Random;

@RestController
@CrossOrigin
@Api(tags = "用户管理")
public class UserController {
    @Resource
    UserServiceImpl userServiceImpl;

//    @PostMapping(value = "UserList")
//    @ApiOperation(value = "用户查询")
//    public List<User>  queryUserList() {
//        return userServiceImpl.findAllUserList();
//    }
    @CrossOrigin(maxAge = 24*60*60)
    @PostMapping(value = "/smsSend")
    @ApiOperation("短信发送")
    @ResponseBody
    public Result sendSmsController(HttpServletRequest request, String telephone){
        SendStatus[] status = userServiceImpl.SendSmsService(request,telephone);
        if (status!=null) {
            return Result.success(Constants.CODE_200,"短信发送成功");
        } else {
            return Result.errorSms();
        }
    }
    //传入短信构建的session
    @CrossOrigin(maxAge = 24*60*60)
    @PostMapping("/signUpSms")
    @ApiOperation("短信注册")
    public Result signUpSmsController(HttpServletRequest requestSign,String telephoneSign,String verifyCodeSign){
        return userServiceImpl.signupService(requestSign,telephoneSign,verifyCodeSign);
    }
    //传入短信构建的session
    @CrossOrigin(maxAge = 24*60*60)
    @PostMapping("/loginSms")
    @ApiOperation("短信登录")//传入user.telephone 和 verifyCode
    public Result loginSmsController(HttpServletRequest requestLogin,String telephoneLogin,@RequestParam String verifyCodeLogin){
        return userServiceImpl.loginsmsService(requestLogin,telephoneLogin,verifyCodeLogin);
    }
    @CrossOrigin(maxAge = 24*60*60)
    @PostMapping("/loginPwd")
    @ApiOperation("密码登录")//前端传入对象，后端返回同意结果封装对象Result（data，statusCode，msg）
    public Result loginPwdController(@RequestBody User user){
        return userServiceImpl.loginPwdService(user);
    }
    @PostMapping(value = "allUser")
    @ApiOperation("用户查询")
    public List<User> FA(){
//        List<User> userList=userService.findAll();
        return userServiceImpl.findAll();
    }
    @PostMapping(value = "findUser")
    @ApiOperation("用户姓名查询")
    public List<User> findn(@RequestBody User user){
//        List<User> userList=userService.findn(username);
        return userServiceImpl.findname(user);
    }
    @PostMapping(value = "insert")
    @ApiOperation("添加用户")
    public boolean addUser(@RequestBody User user) {
//        List<User> userList = userService.addUser(username, email, password, sex, province, city, country);
        return userServiceImpl.addUser(user);
    }
    @PostMapping(value = "delete")
    @ApiOperation("用户删除")
    public boolean delete(int id){
//        List<User> userList=userService.deleteUser(id);
        return userServiceImpl.deleteUser(id);
    }
    @PostMapping(value = "update")
    @ApiOperation("用户修改")
    public boolean update(@RequestBody User user){
//        List<User> userList=userService.updateUser(username, password);
        return userServiceImpl.updateUser(user);
    }
    

}
